package com.banmao.algorithm.No901To1100.No1047;

import java.util.Stack;

public class Solution1 {

    public String removeDuplicates(String s) {

        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        for (char aChar : chars) {
            if(stack.isEmpty()) {
                stack.push(aChar);
                continue;
            }
            Character peek = stack.peek();
            if(peek == aChar) {
                // 重复项，不push，并且pop
                stack.pop();
            } else {
                stack.push(aChar);
            }
        }

        char[] chars1 = new char[stack.size()];
        for (int i = chars1.length - 1; i >= 0; i--) {
            chars1[i] = stack.pop();
        }

        return String.valueOf(chars1);

    }

}
